package files;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Example01 {

	public static void main(String[] args) {
		
		try {
			FileWriter writer = new FileWriter(new File("numbers.txt"));			
			for (int i = 0; i < 10; i++) {
				writer.write(""+i+"\n");
			}			
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();	//quando è utilizzato da un altro pgm
		}
		
		
		try {				//prende in input un qualsiasi reader e gli aggiunge la gestione per righe
			BufferedReader reader = new BufferedReader(new FileReader(new File("numbers.txt")));			
			String line = reader.readLine();
			while (line!=null) {
				System.out.println(line);
				line = reader.readLine();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();	//quando non c'è
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}
}
